import settings from '../settings'
import { getAuthen } from '@/utils/getAuthen'



// 带Origin后缀的通过getter获取
export const state = () => ({
  pointInfo: {},
  wareList: [],
  wareItemOrigin: undefined,
})

export const getters = {
  findWare1: (state) => id => state.wareList.find((item)=>{
    return item.id.toString() === id.toString();
  }),
  findWare: (state) => id => state.wareList.find((item)=>{
    if(!item){
      return false;
    }
    console.log(item);
    return item.id.toString() === id.toString();
  })
}

export const mutations = {
  setPointInfo(state, pointInfo) {
    state.pointInfo = pointInfo
  },
  setWareList(state, wareList){
    state.wareList = wareList
  }
}

export const actions = {
  getPointInfo({ commit, state, rootGetters }) {
    return this.$axios.$get("/getCustomerPointsInfo", {
      params: {
        mobilePhone: rootGetters["authen/phone"],
        enterpriseId: rootGetters["authen/enterpriseId"],
      },
    }).then((res) => {
      if (res.retCode === 0) {
        commit("setPointInfo", res.data);
      }
    });
  },
  getWareList({ commit, state, rootGetters },id) {
    console.log("state",id);
    return this.$axios
      .$get("/getIntegralWaresInfoList", {
        params: {
          stationId: id,
        },
      })
      .then((res) => {
        if (res.retCode == 0) {
          commit("setWareList", res.data)
        }
      });
  },
  getPointsRecordList({ commit, state, rootGetters },params){
    return this.$axios.$get("/getCustomerPointsInfogetCustomerPointsRecordList",{
      params
    })
  }
  
}